using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CloneObj : MonoBehaviour
{
    public GameObject sourceObject; // 拖入原始已烘焙的箱子

    void Start()
    {
        // Renderer sourceRenderer = sourceObject.GetComponent<Renderer>();
        // Renderer targetRenderer = GetComponent<Renderer>();
        //
        // targetRenderer.lightmapIndex = sourceRenderer.lightmapIndex;
        // targetRenderer.lightmapScaleOffset = sourceRenderer.lightmapScaleOffset;
    }
    // Start is called before the first frame update
 
    GameObject obj;
    // Update is called once per frame
    void Update()
    {
        if (obj)
        {
            //随机移动this.obj的位置
            Vector3 randomPosition = new Vector3(
                Random.Range(-5f, 5f),
                Random.Range(0f, 2f),
                Random.Range(-5f, 5f)
            );

            obj.transform.position = randomPosition;
        }
    }

    public void CloneObject()
    {
        GameObject obj = Instantiate(sourceObject, transform.position, transform.rotation);

        Renderer sourceRenderer = sourceObject.GetComponent<Renderer>();
        Renderer targetRenderer = obj.GetComponent<Renderer>();
        targetRenderer.lightmapIndex = 0;// sourceRenderer.lightmapIndex;
        // targetRenderer.lightmapScaleOffset = new Vector4(0.4262502f, 0.4262502f,-0.02061369f, 0.3856363f);// sourceRenderer.lightmapScaleOffset;
        targetRenderer.lightmapScaleOffset = new Vector4(0.4262502f, 0.4262502f,-0.02061369f, -0.02061369f);


        // targetRenderer.lightmapIndex = sourceRenderer.lightmapIndex;
        // targetRenderer.lightmapScaleOffset = sourceRenderer.lightmapScaleOffset;


        //设置随机位置
        Vector3 randomPosition = new Vector3(
            Random.Range(-5f, 5f),
            Random.Range(0f, 2f),
            Random.Range(-5f, 5f)
        );
        obj.transform.position = randomPosition;

        this.obj = obj;
    }
}
